// 数据检查
function check_datas(methodName, seq) {
    if (methodName === 'check_indb_table') {
        show(seq + 10);
    } else {
        show(seq);
    }

    $.ajax({
        type:'POST',
        url: '/main/'+ methodName,
        //data: data,
        //dataType: 'json',
        success: function (data) {
            var newdata = data.result;
            if (newdata[0] == '('){
                alert("执行报错：" + newdata);
            }
            if (methodName == 'check_indb_table'){
                for (var j = 0; j < newdata.length; j++){
                    var divStr = $("#div_1" + j);
                    divStr.empty();
                    var apanStr = [];
                    for (var i = 0; i < newdata[j].length; i++) {
                        if (newdata[j][i] == 0) {
                            apanStr[i] = $("<font color=\"#90ee90\"><span class=\"glyphicon glyphicon-ok\"></span>&nbsp&nbsp</font>")
                        } else {
                            apanStr[i] = $("<font color=\"red\"><span class=\"glyphicon glyphicon-remove\"></span>&nbsp&nbsp</font>")
                        }
                        divStr.append(apanStr[i]);
                    }
                }
            /*} else if (methodName == 'check_two_balance'){
                if (newdata[0] == '('){
                    alert("执行报错：" + newdata);
                }
                for (var j = 0; j < newdata.length; j++){
                    var divStr = $("#div_2" + j);
                    divStr.empty();
                    var apanStr = new Array();
                    for (var i = 0; i < newdata[j].length; i++) {
                        if (newdata[j][i] == 0) {
                            apanStr[i] = $("<font color=\"#90ee90\"><span class=\"glyphicon glyphicon-ok\"></span>&nbsp&nbsp</font>")
                        } else {
                            apanStr[i] = $("<font color=\"red\"><span class=\"glyphicon glyphicon-remove\"></span>&nbsp&nbsp</font>")
                        }
                        divStr.append(apanStr[i]);
                    }
                }*/
            } else {
                if (methodName == 'check_cycle' && newdata.length != 5){
                        alert("执行报错：" + newdata);
                } else {
                    var divStr = $("#div_" + seq);
                    divStr.empty();
                    var apanStr = [];
                    for (var i = 0; i < newdata.length; i++) {
                        if (newdata[i] == 0) {
                            apanStr[i] = $("<font color=\"#90ee90\"><span class=\"glyphicon glyphicon-ok\"></span>&nbsp&nbsp</font>")
                        } else {
                            apanStr[i] = $("<font color=\"red\"><span class=\"glyphicon glyphicon-remove\"></span>&nbsp&nbsp</font>")
                        }
                        divStr.append(apanStr[i]);
                    }
                }
            }
            hide()
        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert("系统异常 - " + jqXHR.status + " - " + errorThrown +  "\n" + jqXHR.responseText);
            hide()
        }
    });
}

// 数据统计
function count_datas(methodName, seq) {
    show(seq);
    $.ajax({
        type:'POST',
        url: '/main/' + methodName,
        //data: data,
        dataType: 'json',
        success: function (data) {
            var newdata = data.result;
            if (newdata.length != 4){
                alert("执行报错：" + newdata);
            } else {
                var divStr = $("#div_" + seq);
                divStr.empty();
                var apanStr = [];
                for(var i=0;i<newdata.length;i++){
                    apanStr[i] = $(`<font><span class="label label-info">${newdata[i]}</span>&nbsp</font>`);
                    divStr.append(apanStr[i]);
                }
            }
            hide()
        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert("系统异常 - " + jqXHR.status + " - " + errorThrown +  "\n" + jqXHR.responseText);
            /*弹出jqXHR对象的信息
            alert(jqXHR.responseText);
            alert(jqXHR.status);
            alert(jqXHR.readyState);
            alert(jqXHR.statusText);*/
            /*弹出其他两个参数的信息
            alert(textStatus);
            alert(errorThrown);*/
            hide()
        }
    });
}

// 数据修改
function update_datas(methodName, param, seq) {
    show(seq);
    $.ajax({
        type:'POST',
        url: '/main/'+ methodName,
        data: {param:param},
        dataType: 'json',
        success: function (data) {
            var divStr = $("#div_" + seq);
            divStr.empty();
            var apanStr = $("<font color=\"#90ee90\"><span class=\"glyphicon glyphicon-ok\"></span>&nbsp&nbsp</font><span> 修改成功，重启进程生效</span>");
            divStr.append(apanStr);
            hide()
        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert("系统异常 - " + jqXHR.status + " - " + errorThrown +  "\n" + jqXHR.responseText);
            hide()
        }
    });
}

// 备份进程检查
function backup_progress(methodName, seq) {
    show(seq);
    $.ajax({
        type:'POST',
        url: '/main/'+ methodName,
        success: function (data) {
            var newdata = data.result;
            var divStr = $("#div_" + seq);
            divStr.empty();
            var apanStr = [];

            for (var j = 0; newdata.length > j; j++) {
                var result = newdata[j].split(":");
                if (newdata[1] == 0) {
                    apanStr[j] = $("<span>" + result[0] + "<\span>&nbsp&nbsp<font color=\"#90ee90\"><span class=\"glyphicon glyphicon-ok\"></span></font><span> 完成 </span>");
                } else {
                    apanStr[j] = $("<span>" + result[0] + "<\span>&nbsp&nbsp<font color=\"red\"><span class=\"glyphicon glyphicon-remove\"></span></font><span> 未完成 </span>");
                }
                divStr.append(apanStr[j]);
            }
            hide()
        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert(jqXHR.status + " - " + errorThrown +  "\n" + jqXHR.responseText);
            hide()
        }
    });
}
